package com.yanqu.road.logic.pb;


import com.yanqu.road.entity.inn.UserDishes;
import com.yanqu.road.entity.inn.UserInnInfo;
import com.yanqu.road.pb.inn.InnProto;

import java.util.List;

public class InnPb {
    public static InnProto.DishesTempListMsg.Builder  parseDishesListMsg(List<UserDishes> list) {

        InnProto.DishesTempListMsg.Builder listMsg = InnProto.DishesTempListMsg.newBuilder();

        if(null != list) {
            for (UserDishes dishes : list) {
                InnProto.DishesTempMsg.Builder msg = parseDishesMsg(dishes);
                if (null != msg) {
                    listMsg.addDishesInfoList(msg);
                }
            }
        }
        return listMsg;
    }

    private static InnProto.DishesTempMsg.Builder parseDishesMsg(UserDishes dishes) {
        InnProto.DishesTempMsg.Builder dishesBuilder = InnProto.DishesTempMsg.newBuilder();
        dishesBuilder.setDishesLv(dishes.getLevel());
        dishesBuilder.setDishesId(dishes.getDishesId());
        dishesBuilder.setCurrentCookNum(dishes.getCurrentCookNum());

        return dishesBuilder;
    }

    public static InnProto.InnDetailInfoMsg parseInnInfo(UserInnInfo userInnInfo, long cookExp) {
        InnProto.CookInfoMsg.Builder cookInfoBuilder = InnProto.CookInfoMsg.newBuilder();
        cookInfoBuilder.setStartTime(userInnInfo.getCookStartTime())
                .setCookExp(cookExp)
                .setDishesId(userInnInfo.getDishesId())
                .setDishesNum(userInnInfo.getDishesNum())
                .setIsHot(userInnInfo.isHot()?1:0)
                .setPatronsId(userInnInfo.getPatronsId());
        if(userInnInfo.isHot()){
            cookInfoBuilder.setHotRate(userInnInfo.getHotRate());
        }
        InnProto.InnDetailInfoMsg.Builder builder = InnProto.InnDetailInfoMsg.newBuilder();
        builder.setOpen(userInnInfo.getCookStartTime()>0?1:0);
        builder.setLastMoney(userInnInfo.getLastValue());
        builder.setLastClickMoneyTime(userInnInfo.getLastClickMoneyTime());
        builder.setCookInfo(cookInfoBuilder);
        return builder.build();
    }
}
